<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../commons/commons.jsp"%>
<!DOCTYPE html>

<head>
    <meta charset="utf-8" />
    <title>Data Tables</title>
</head>
<body>
<div class="page-body">
    <div class="row">
        <div class="col-xs-12 col-md-12">
            <div class="widget">
                <div class="widget-header ">
                    <span class="widget-caption">
        				预约安排保姆
                    </span>
                </div>
                <div class="widget-body">
                    <form id="saveOrUpdate" class="form-horizontal form-bordered" role="form" method="get" action="${ ctx}/nannyappli/oper.do">
                    	<input type="hidden" name="id" value="${bean.id }"/>
                    	<div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">预约服务类型</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="${serviceContent.serviceName}" disabled/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">预约人名称</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="${bean.contacts}" disabled/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">预约人联系方式</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="${bean.contactMethod}" disabled/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">服务地址</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="${bean.serviceAddress}" disabled/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">服务周期</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="${bean.serviceCycle}月" disabled/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">服务开始时间</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="<fmt:formatDate value="${bean.serviceTime }" pattern="yyyy-MM-dd" />" disabled/>
	                        </div>
                        </div>
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">备注</label>
	                        <div class="col-sm-10">
	                        	<input type="text" class="form-control" value="${bean.remarks}" disabled/>
	                        </div>
                        </div>
                        
                        <div class="form-group">
	                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">选择保姆</label>
	                        <div class="col-sm-5">
	                        	
	                        	<select id="nannyid" name="nannyid" class="form-control" style="width: 100%">
	                        		<option value="0">请选择保姆</option>
									<c:forEach var="item" items="${nannylist}">
										<c:choose>
                                          	<c:when test="${item.id==bean.arrangeNannyId}">
                                          		<option value="${item.id}" selected>${item.truename }(${item.phone })</option>
                                          	</c:when>
                                          	<c:otherwise>
                                          		<option value="${item.id}">${item.truename }(${item.phone })</option>
                                          	</c:otherwise>
                                        </c:choose>
									</c:forEach>
								</select>
							</div>
							 <div class="col-sm-5">
							 	<c:if test="${bean.arrangeNannyId==null || bean.arrangeNannyId =='0'}">
                                       <img id="nannyimg" src="https://www.cornergj.top/favicon/logo.png" style="width:200px;height:200px">
                                </c:if>
                                <c:if test="${bean.arrangeNannyId != null}">
                                	<c:forEach var="item2" items="${nannylist}">
                                		<c:if test="${item2.id==bean.arrangeNannyId}">
                                       		<img id="nannyimg" src="${ item2.nannyUrl}" style="width:200px;height:200px">
                                       </c:if>
                                    </c:forEach>
                                </c:if>
							</div>
                        </div>
                        
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <a class="btn btn-palegreen" href="javascript:save()">确定安排保姆</a>
                                <a class="btn btn-palegreen" href="${ctx}/order/list.do?userId=${bean.userId}">返回</a>
                            </div>
                     	</div>
                 	</form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
	$(document).ready(function () {
	    $('#picUpload').bootstrapValidator();
	});
	$("#nannyid").change(function(){
		if($("#nannyid").val()!='0'){
			var url = '${ctx }' + "/nanny/getnannyinfo.do";
			var sendData = {
				"nid":$("#nannyid").val()
			};
			$.get(url, sendData, function(backData) {
				if (backData.status == 1) {
					$("#nannyimg").attr("src",backData.data);
				} else {
					warningAlert("操作失败，请稍后重试");
				}
			});
		}else{
			$("#nannyimg").attr("src","https://www.cornergj.top/favicon/logo.png");
		}
	});
	
	var save =function(){
		if($("#nannyid").val()=='0'){
			warningAlert("请先安排一个保姆人员");
		}else{
		bootbox.confirm("你确定为该预约服务安排该保姆吗", function(result) {
			if(result){
				var url = '${ctx }' + "/order/arrangenanny.do";
			var sendData = {
				"oid" :${bean.id },
				"nid":$("#nannyid").val()
			};
			$.get(url, sendData, function(backData) {
				if (backData.status == 1) {
					window.location.href="${ctx }/order/list.do?userId=${bean.userId }";
				} else {
					warningAlert("安排操作失败，请稍后重试");
				}
			});
			}
		});
		}
	}

</script>
</html>
